from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from djiape.adquisitions.models import Supplier, TransactionType
from djiape.entities.models import Currency

class Journal(models.Model):
    supplier = models.ForeignKey(Supplier, verbose_name=_('supplier'))
    ap_operation = models.ForeignKey(TransactionType, verbose_name=_('transaction'), related_name='ap_operation')
    folio = models.CharField(_('folio'), max_length=10)
    date = models.DateTimeField(_('date'), auto_now_add=True)
    ap_aux_oper = models.ForeignKey(TransactionType, verbose_name=_('transaction'), blank=True, null=True, related_name='ap_aux_oper')
    aux_fol = models.CharField(_('reference'), max_length=10, blank=True, null=True)
    credit_term = models.IntegerField(_('credit terms'), default=0)
    ap_currency = models.ForeignKey(Currency, verbose_name=_('currency'), related_name='ap_currency')
    rate = models.DecimalField(_('rate'), max_digits=14, decimal_places=2, default=1)
    total = models.DecimalField(_('total'), max_digits=14, decimal_places=2)
    tax = models.DecimalField(_('tax'), max_digits=14, decimal_places=2)
    credit = models.DecimalField(_('credit'),max_digits=14, decimal_places=2, blank=True, null=True, editable=False)
    debit = models.DecimalField(_('debit'),max_digits=14, decimal_places=2, blank=True, null=True, editable=False)
    gl_operation = models.IntegerField(_('gl operation'), default=0)
    pu_operation = models.IntegerField(_('pu operation'), default=0)
    status = models.CharField(_('status'), max_length=1, default='N')
    ap_user = models.ForeignKey(User, verbose_name=_('user'), related_name='ap_user')
